package com.ynet.middleground.approve.identity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.Picture;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.UserQueryImpl;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.activiti.engine.impl.persistence.entity.UserEntityImpl;
import org.activiti.engine.impl.persistence.entity.UserEntityManager;
import org.springframework.stereotype.Component;

import com.ynet.core.exception.BusinessException;

/**
 * @author liulx
 * @description 自定义用户管理器
 * @date 2019-11-19 14:04
 */
@Component
public class CustomUserEntityManager implements UserEntityManager {

    @Override
    public User createNewUser(String s) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void updateUser(User user) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public List<User> findUserByQueryCriteria(UserQueryImpl userQuery, Page page) {
        /*List<User> result = new ArrayList<>();
        if (userQuery.getId() != null) {
            result.add(findById(userQuery.getId()));
            return result;
        } else if (userQuery.getFullNameLike() != null) {
            final String fullNameLike = userQuery.getFullNameLike().replaceAll("%", "");
        } else {
            throw new BusinessException("当前不支持查询用户信息", "00001");
        }
        return result;*/
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public long findUserCountByQueryCriteria(UserQueryImpl userQuery) {
        return findUserByQueryCriteria(userQuery, null).size();
    }

    /**
     *
     * 
     * @param s
     * @return
     */
    @Override
    public List<Group> findGroupsByUser(String s) {
        List<Group> groups = new ArrayList<>(1);
        Group group = new GroupEntityImpl();
        group.setId("001");
        group.setName("dept_001");
        group.setType("groups");
        return groups;
    }

    @Override
    public UserQuery createNewUserQuery() {
        return new UserQueryImpl(Context.getProcessEngineConfiguration().getCommandExecutor());
    }

    @Override
    public Boolean checkPassword(String s, String s1) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public List<User> findUsersByNativeQuery(Map<String, Object> map, int i, int i1) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public long findUserCountByNativeQuery(Map<String, Object> map) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public boolean isNewUser(User user) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public Picture getUserPicture(String s) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void setUserPicture(String s, Picture picture) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void deletePicture(User user) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public UserEntity create() {
        throw new BusinessException("该功能未实现", "00001");
    }

    /**
     *
     * 
     * @param s
     *            青岛港用户ID
     * @return 用户对象
     */
    @Override
    public UserEntity findById(String s) {
        UserEntityImpl userEntity = new UserEntityImpl();
        userEntity.setFirstName("LLLL");
        userEntity.setLastName("XXX");
        userEntity.setEmail("123@1234.com");
        userEntity.setPassword("123");
        userEntity.setId("123");
        userEntity.setRevision(0);
        userEntity.setInserted(false);
        userEntity.setUpdated(false);
        userEntity.setDeleted(false);
        return userEntity;
    }

    @Override
    public void insert(UserEntity entity) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void insert(UserEntity entity, boolean b) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public UserEntity update(UserEntity entity) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public UserEntity update(UserEntity entity, boolean b) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void delete(String s) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void delete(UserEntity entity) {
        throw new BusinessException("该功能未实现", "00001");
    }

    @Override
    public void delete(UserEntity entity, boolean b) {
        throw new BusinessException("该功能未实现", "00001");
    }
}
